package com.zqs.service.impl;

import com.zqs.entity.Product;
import com.zqs.mapper.ProductMapper;
import com.zqs.service.ProductService;
import com.zqs.service.ex.ProductNothingnessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> categoryList(Integer cid, Integer bid) {
        List<Product> productList = productMapper.findByCidAndBid(cid, bid);
        if (productList == null){
            throw new ProductNothingnessException("商品不存在!");
        }
        return productList;
    }

    @Override
    public Product carDetail(Integer pid) {
        Product product = productMapper.findByPid(pid);
        if (product == null && product.getState()==1){
            throw new ProductNothingnessException("商品不存在!");
        }
        return product;
    }

    @Override
    public List<Product> findAllByPriceDesc() {
        List<Product> productList = productMapper.findAllByPriceDesc();
        if (productList == null){
            throw new ProductNothingnessException("商品不存在!");
        }
        return productList;
    }

    @Override
    public List<Product> findAllByPriceAsc() {
        List<Product> productList = productMapper.findAllByPriceAsc();
        if (productList == null){
            throw new ProductNothingnessException("商品不存在!");
        }
        return productList;
    }

    @Override
    public List<Product> findAllByTime() {
        List<Product> productList = productMapper.findAllByTime();
        if (productList == null){
            throw new ProductNothingnessException("商品不存在!");
        }
        return productList;
    }

    @Override
    public List<Product> findAll() {
        List<Product> productList = productMapper.findAll();
        if (productList == null){
            throw new ProductNothingnessException("商品不存在!");
        }
        return productList;
    }

    @Override
    public List<Product> findByProductName(String title) {
        List<Product> productList = productMapper.findByProductName(title);
        if (productList == null){
            throw new ProductNothingnessException("商品不存在!");
        }
        return productList;
    }
}
